package zjc.bookkeeping.fragment.statistics;

import static java.security.AccessController.getContext;

import android.content.Context;
import android.database.sqlite.SQLiteCursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.text.DecimalFormat;
import java.util.Date;
import java.util.List;

import zjc.bookkeeping.R;

public class ReportListAdapter extends BaseAdapter {
    private Context context;

    List<ReportListItemData> data;




    public ReportListAdapter(Context context, List<ReportListItemData> data) {
        super();
        this.context=context;
        this.data = data;
    }


    public Context getContext() {
        return context;
    }



    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public ReportListItemData getItem(int i) {
        return data.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        Log.i("i:",String.valueOf(i));
        LinearLayout ll=null;
        ll=(LinearLayout) LayoutInflater.from(this.getContext()).inflate(R.layout.report_list_item, null);
        ReportListItemData dt = getItem(i);
        TextView date = (TextView) ll.findViewById(R.id.date);
        TextView spending = (TextView) ll.findViewById(R.id.spending);
        TextView income = (TextView) ll.findViewById(R.id.income);
        TextView balance = (TextView) ll.findViewById(R.id.balance);
        date.setText(dt.getDate());
        DecimalFormat df = new DecimalFormat("0.00");// 保留两位小数

        spending.setText(df.format(dt.getSpending()));
        income.setText(df.format(dt.getIncome()));
        balance.setText(df.format(dt.getBalance()));
        return ll;

    }
}
